﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using PowerCreator.LMS.Grade.Entity;
using PowerCreator.LMS.Common.Script;
using PowerCreator.LMS.Web.Grade;
using PowerCreator.LMS.Web.Course;
using PowerCreator.LMS.Course.Entity;
using PowerCreator.LMS.ViewQuery;

public partial class sysadmin_GradeManager_ManagerUserGrade : PowerCreator.LMS.Web.Base.BasePage
{
    GradeManager objGradeManager = new GradeManager();
    ViewQuery objViewQuery = new ViewQuery();
    Course objCourseManager = new Course();

    //const string SEARCH_TTEACHER_TGRADE_TUSER_TRESOURCE = "select DISTINCT TUser.UserID,TUser.UserName,TStudent.StudentName,TResource.ResourceID,TResource.ResourceName from TUser,TGrade,TStudent,TResource" +

    //                                            " where TUser.UserID=TGrade.FKGradeUserID and TStudent.StudentId=TUser.UserID and TResource.ResourceID=TGrade.FKGradeResourceID ";

    const string SEARCH_TTEACHER_TGRADE_TUSER_TRESOURCE = "select VIEW_AllUser.UserID,VIEW_AllUser.RealName,TResource.ResourceID,TResource.ResourceName from VIEW_AllUser inner join TResource on VIEW_AllUser.RealName=TResource.ResourceAuthor where 1=1 ";
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            InitPage();
            string search = GetSearch();
            BinderPager(search);
            BinderPG(search, 1);
        }
        
    }

    protected override void InitPage()
    {
        lbl_InfoTitle_ManagerUserGrade.Text =GetLanageValueByKey("lab_AddSkill_ManagerUserGrade", PowerCreator.LMS.Language.LanagetItemType.Page);
        //lbl_ManagerDownload.Text = "新下载资源列表";
        
        btnSearch.Text = GetLanageValueByKey("btn_Search", PowerCreator.LMS.Language.LanagetItemType.Page);

        
        base.InitPage();

        //btnAddNew.Visible = false;
        //if (IsLicensed(PowerCreator.LMS.Action.Core.ActionInfo.AddJob))
        //    btnAddNew.Visible = true;

    }
    private string GetSearch()
    {
        string search = SEARCH_TTEACHER_TGRADE_TUSER_TRESOURCE;
        if (!string.IsNullOrEmpty(txt_DownLoadTitle.Text))
            search += " and VIEW_AllUser.RealName like '%" + txt_DownLoadTitle.Text.Trim() + "%' or TResource.ResourceName like '%" + txt_DownLoadTitle.Text.Trim() + "%'";
        return search;
    }

    protected void BinderPager(string search)
    {
        AspNetPager1.RecordCount = objViewQuery.Count(search);
        AspNetPager1.PageSize = LMSPageSize;
    }
    private void BinderPG(string search, int pageIndex)
    {
        DataTable dt = objViewQuery.Query(search, LMSPageSize, pageIndex);
        dt.Columns.Add("url");
        for (int i = 0; i < dt.Rows.Count; i++)
        {
            dt.Rows[i]["url"] = "UserID=" + dt.Rows[i]["UserID"].ToString() + "&ResourceID=" + dt.Rows[i]["ResourceID"].ToString();
        }
        rptDownload.DataSource = dt;
        rptDownload.DataBind();
        
        PreAspNetPager(AspNetPager1);
    }

    protected void btnSearch_Click(object sender, EventArgs e)
    {
        string search = GetSearch();
        BinderPager(search);
        BinderPG(search, 1);
    }


    protected void AspNetPager1_PageChanged(object sender, EventArgs e)
    {
        string search = GetSearch();
        BinderPG(search, AspNetPager1.CurrentPageIndex);
    }
    protected void rptDownload_ItemCommand(object source, RepeaterCommandEventArgs e)
    {
        Label lbl_msg = (Label)e.Item.FindControl("lbl_msg");

        if (e.CommandName.ToLower() == "see")
        {
            string url = "UserGradeStatistics.aspx?"+e.CommandArgument.ToString();
            Script.RedirectURL(url); 
        }
      

    }
    protected void rptDownload_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
    }
}
